<?php

  // Database connection settings
  define("PG_DB"  , "balkan_20090317_postgis");
  define("PG_HOST", "192.168.2.161");
  define("PG_USER", "postgres");
  define("PG_PORT", "5432");
  define("PG_PWD", "postgres");

  $wktFeat = $_REQUEST["wktstr"];
  $wktType = $_REQUEST["wktType"];
  $nameStr = $_REQUEST["nameStr"];
  $descStr = $_REQUEST["descStr"];

  //$wktFeat = str_replace("--", " ", $wktFeat);


  //echo $wktFeat[0];

  $con = pg_connect("dbname=".PG_DB." host=".PG_HOST." user=".PG_USER." password=".PG_PWD);

  for ($counter = 0; $counter < sizeof($wktFeat); $counter += 1)
  {
		$wktFeat[$counter] = str_replace("--", " ", $wktFeat[$counter]);
		if ($wktType[$counter] == "POLYGON")
		{
			$sql = "insert into companyvectors (id, name, descr, polygon_geom,mobiliz_gis_server,company_id) values (nextval('companyvectors_id_seq'), '".$nameStr[$counter]."', '".$descStr[$counter]."' ,GeomFromText('".$wktFeat[$counter]."', 4326),'85.235.85.86',33793)";
		}
		else if ($wktType[$counter] == "LINESTRING")
		{
			$sql = "insert into companyvectors (id, name, descr, line_geom,mobiliz_gis_server,company_id) values (nextval('companyvectors_id_seq'), '".$nameStr[$counter]."', '".$descStr[$counter]."' , GeomFromText('".$wktFeat[$counter]."', 4326),'85.235.85.86',33793)";
		}
		else if ($wktType[$counter] == "POINT")
		{
			$sql = "insert into companyvectors (id, name, descr,point_geom,mobiliz_gis_server,company_id) values (nextval('companyvectors_id_seq'), '".$nameStr[$counter]."', '".$descStr[$counter]."' , GeomFromText('".$wktFeat[$counter]."', 4326),'85.235.85.86',33793)";
		}

  		echo $sql;
  		$query = pg_query($con,$sql);

  }

  pg_close($con);

  //echo $sql;

  //$query = pg_query($con,$sql);
  //pg_close($con);

?>